#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
struct TreeNode 
{
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};
typedef struct TreeNode TreeNode;
int TreeNodeSize(TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }
    return 1 + TreeNodeSize(root->left) + TreeNodeSize(root->right);
}
void preOrder(TreeNode* root, int* arr, int* i)
{
    if (root == NULL)
    {
        return;
    }
    arr[(*i)++] = root->val;
    preOrder(root->left, arr, i);
    preOrder(root->right, arr, i);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize)
{
    *returnSize = TreeNodeSize(root);
    int* arr = (int*)malloc(sizeof(int) * (*returnSize));
    int i = 0;
    preOrder(root, arr, &i);
    return arr;
}